package model;

import java.io.Serializable;

import javax.persistence.*;

import dtos.ExcursionDTO;
import dtos.ExcursionPersTPDTO;

import java.util.LinkedList;
import java.util.List;


/**
 * The persistent class for the excursion database table.
 * 
 */
@Entity
@NamedQuery(name="Excursion.findAll", query="SELECT e FROM Excursion e")
public class Excursion implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	private int excursionID;

	private String arrivalPlace;

	private int cost;

	private String meetingPlace;

	private String meetingTime;

	private String name;

	//bi-directional many-to-one association to ExcursionPredTP
	@OneToMany(mappedBy="excursion", cascade={CascadeType.PERSIST})
	private List<ExcursionPredTP> excursionPredTps;
	
	//bi-directional many-to-one association to ExcursionPersTP
		@OneToMany(mappedBy="excursion", cascade={CascadeType.PERSIST})
		private List<ExcursionPersTP> excursionPersTps;

	public Excursion() {
		this.excursionPersTps = new LinkedList<ExcursionPersTP>();
	}
	
	public Excursion(ExcursionDTO excursion){
        
        this.excursionID        = excursion.getExcursionID();
        this.name    = excursion.getName();
        this.arrivalPlace     = excursion.getArrivalPlace();        
        this.cost     = excursion.getCost();
        this.meetingPlace = excursion.getMeetingPlace();
        this.meetingTime = excursion.getMeetingTime();

    }

	public ExcursionDTO getDTO(){
		ExcursionDTO e = new ExcursionDTO();
		e.setArrivalPlace(this.arrivalPlace);
		e.setCost(this.cost);
		e.setExcursionID(this.excursionID);
		e.setMeetingPlace(this.meetingPlace);
		e.setMeetingTime(this.meetingTime);
		e.setName(this.name);
		//e.setExcursionPersTps(this.getExcursionPersTpsDTO());
		
		return e;
		
	}
	public ExcursionDTO getDTOWithoutExcursionPersTP() {
		ExcursionDTO e = new ExcursionDTO();
		e.setArrivalPlace(this.arrivalPlace);
		e.setCost(this.cost);
		e.setExcursionID(this.excursionID);
		e.setMeetingPlace(this.meetingPlace);
		e.setMeetingTime(this.meetingTime);
		e.setName(this.name);
		
		return e;
	}
	
	public int getExcursionID() {
		return this.excursionID;
	}

	public void setExcursionID(int excursionID) {
		this.excursionID = excursionID;
	}

	public String getArrivalPlace() {
		return this.arrivalPlace;
	}

	public void setArrivalPlace(String arrivalPlace) {
		this.arrivalPlace = arrivalPlace;
	}

	public int getCost() {
		return this.cost;
	}

	public void setCost(int cost) {
		this.cost = cost;
	}

	public String getMeetingPlace() {
		return this.meetingPlace;
	}

	public void setMeetingPlace(String meetingPlace) {
		this.meetingPlace = meetingPlace;
	}

	public String getMeetingTime() {
		return this.meetingTime;
	}

	public void setMeetingTime(String meetingTime) {
		this.meetingTime = meetingTime;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<ExcursionPersTP> getExcursionPersTps() {
		return this.excursionPersTps;
	}

	public void setExcursionPersTps(List<ExcursionPersTP> excursionPersTps) {
		this.excursionPersTps = excursionPersTps;
	}
	
	public List<ExcursionPredTP> getExcursionPredTps() {
		return this.excursionPredTps;
	}

	public void setExcursionPredTps(List<ExcursionPredTP> excursionPredTps) {
		this.excursionPredTps = excursionPredTps;
	}

	public ExcursionPredTP addExcursionPredTp(ExcursionPredTP excursionPredTp) {
		getExcursionPredTps().add(excursionPredTp);
		excursionPredTp.setExcursion(this);

		return excursionPredTp;
	}

	public ExcursionPredTP removeExcursionPredTp(ExcursionPredTP excursionPredTp) {
		getExcursionPredTps().remove(excursionPredTp);
		excursionPredTp.setExcursion(null);

		return excursionPredTp;
	}
	
	public List<ExcursionPersTPDTO> getExcursionPersTpsDTO() {
		List<ExcursionPersTPDTO> res = new LinkedList<ExcursionPersTPDTO>();
		for (ExcursionPersTP p : this.excursionPersTps){
			res.add(p.getDTO());
		}
		return res;
		
	}


	public boolean isAtPlace(String place) {
		return (this.arrivalPlace.equals(place));
	}

}